package tcln.gxtx.client.utils.async;

import com.google.gwt.user.client.Command;

/**
 * A special "command" for {@link Timer}. This command supports the following functionalities:
 * <ul>
 * <li>It is a runnable command (extends {@link Command}).
 * <li>It supports 'cancel' action on its owner timer via {@link #isCancelled()}.
 * <li>It supports 'suspend' action on its owner timer via {@link #suspend()}
 * </ul>
 * 
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 */
public abstract class TimerCommand implements CancellableCommand {
    protected Timer ownerTimer;

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isCancelled() {
        return false;
    }
    
    /**
     * Suspends its owner timer.
     */
    public final void suspend() {
        ownerTimer.setSuspended(true);
    }
    
    /**
     * Restarts (continues) its owner timer.
     */
    public final void restart() {
        ownerTimer.setSuspended(false);
    }
}
